<template>
  <div id="app">
      <div class="navbar">
        <van-nav-bar
          :title="title"
          :left-text="leftText"
          :right-text="rightText"
          :left-arrow="isLeftArrow"
          @click-left="onClickLeft"
          fixed
        />
      </div>
    <router-view></router-view>
    <Tabbar v-if="isTab"></Tabbar>
  </div>
</template>
<script>
import Tabbar from "@/components/Tabbar.vue";
import { NavBar } from "vant";
export default {
  name: "App",
  data() {
    return {
      title: "",
      leftText: "",
      rightText: "",
      isLeftArrow: false,
      isTab: true,
      transitionName: ""
    };
  },
  components: {
    Tabbar,
    [NavBar.name]: NavBar,
  },
  watch: {
    //使用watch 监听$router的变化
    $route(to, from) {
      this.title = to.meta.title;
      this.isTab = to.meta.isTab;
      if (!to.meta.isTab) {
        this.isLeftArrow = true;
        this.leftText = "返回";
      } else {
        this.isLeftArrow = false;
        this.leftText = "";
      }
    }
  },
  methods: {
    onClickLeft() {
      this.$router.go(-1);
    }
  }
};
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
}

#nav {
  padding: 30px;
}

#nav a {
  font-weight: bold;
  color: #2c3e50;
}

#nav a.router-link-exact-active {
  color: #42b983;
}
.van-icon-arrow-left:before,
.van-nav-bar__text {
  color: #777;
}
p {
  margin: 0;
  padding: 0;
}
</style>
